package com.ibm.ems.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.ems.dao.ParticipantsDAO;
import com.ibm.ems.dto.UserBean;

public class RegistrationDetailsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

   
    public RegistrationDetailsServlet() {
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String fullname=request.getParameter("FullName");
		String eMail=request.getParameter("userEmail");
		String addrs=request.getParameter("userAddress");
		String ph=request.getParameter("userNum");
		long phonenum=Long.parseLong(ph);
		String uName=request.getParameter("userName");
		String password=request.getParameter("userPass");
		System.out.println("Hai this is servlet:)");
		
		UserBean pr=new UserBean();
		
		pr.setFullName(fullname);
		pr.setUserEmail(eMail);
		pr.setUserAddress(addrs);
		pr.setPhonenum(phonenum);
		pr.setUserName(uName);
		pr.setUserPass(password);
		
		ParticipantsDAO pDao=new ParticipantsDAO();
		request.setAttribute("participant", pr);
		//request.setAttribute("error", pr);
		
		try{
			int flag1=pDao.checkUsername(pr);
			if(flag1==1){
			pDao.getParticipantdetails(pr);	
			request.getRequestDispatcher("/participant/Homepage.jsp").forward(request, response);
			}
			else{	
				
				request.setAttribute("error",pr);
				request.getRequestDispatcher("FormRegister.jsp").forward(request, response);  
			    
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
	}

}
